;!function () {
    var form = layui.form, layer = layui.layer;
    form.verify({
        username: [/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/, '用户名为5到16位（字母开始，其他可使用数字，下划线)'],
        password: [/^[\S|\s]{5,20}$/, '密码为5到20位']
    });

    form.on('submit(login)', function (data) {
        layer.msg("网络请求中...");
        myajax("/login.json", "post", data.field,
            function (result) {
                if (result.status == 200) {
                    $.cookie("sessionId", result.sessionId, {expires: 7, path: "/"});
                    window.location.href = "admin.html";
                } else if (result.status == 404) {
                    layer.msg(result.message);
                }
            },
            function () {
                layer.msg("网络请求错误");
            });
        return false;
    });
}();
